home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / banging_the_metal / qdos / qdos4amiga3.lha / C68PATCH_readme < prev    next >
Text File  |  1998-02-24  |  4KB  |  155 lines

  1. Short:    patch C68 programs to be COPYBACK friendly
  2. Author:   Mark J Swift
  3. Version:  1.01
  4. Uploader: msw@blackpool.ac.uk
  5.  
  6.  
  7. This BASIC program patches C68 and C68 compiled programs to work
  8. with 68040 and 68060 processors with COPYBACK enabled.
  9.  
  10.  
  11. ARCHIVE CONTENTS
  12.  
  13.  C68PATCH_bas     - The patcher program.
  14.  C68PATCH_readme  - This file.
  15.  
  16.  
  17. COMPATIBILITY
  18.  
  19. Works on current versions of C68 that I have tried.
  20.  
  21.  
  22. WHY IS IT NECESSARY?
  23.  
  24. On machines with 68040 and 68060 processors, enabling the COPYBACK cache
  25. can give substantial speed increases since memory is only updated from
  26. the caches when absolutely necessary. Thus with COPYBACK enabled, it is
  27. ESSENTIAL to flush the caches out to memory before they are cleared or
  28. disabled.
  29.  
  30. The C68 cache routines are inadequate in this respect.
  31.  
  32. From a disassembly It can be seen that before the compiler relocates
  33. itself, the caches are disabled by the following subroutine:
  34.  
  35. CACHOFF:
  36.         cmpi.b  #$20,$A1(a6)
  37.         bls.s   CACHOFX
  38. *
  39.         movec   cacr,d0
  40. *                 1=data cache enable (>=040)
  41. *                 |               1=instr cache enable (>=040)
  42. *                 |               |   1=clear data cache (030)
  43. *                 |               |   |  1=data cache enable (030)
  44. *                 |               |   |  |    1=clear instr cache (020,030)
  45. *                 |               |   |  |    |  1=instr cache enable(020,030)
  46. *                 |               |   |  |    |  |
  47.         move.l  #%00000000000000000000100000001000,d1
  48.         movec   d1,cacr
  49. *
  50. CACHOFX:
  51.         rts
  52.  
  53. On 030 processors this clears (bits 3 and 11 set) the data and
  54. instruction caches and also disables them (bits 0 and 8 clear).
  55.  
  56. On the >=040 processors the code simply disables the caches. It
  57. does not update the memory from the caches.
  58.  
  59. In most cases on the '040 the code will be sufficient (i.e it usually
  60. works). However on an '040 with COPYBACK enabled the subroutine always
  61. fails - usually with a corrupted return stack.
  62.  
  63. Here is what happens...
  64.  
  65. The subroutine CACHEOFF is called and the return address is pushed on
  66. the stack. However with COPYBACK enabled the return address is written
  67. to the data cache but not written through to memory. Next, the subroutine
  68. disables the caches but does not flush them to memory beforehand. Now
  69. memory does not contain up-to-date information and cache contents are
  70. already lost. This means that the return stack will NOT contain the
  71. correct return address - so the RTS instruction bombs the machine.
  72.  
  73. There is also a section of code that sets the cache to a value passed
  74. in d0. This also fails to flush the caches:
  75.  
  76. SETCACH:
  77.         tst.l   d0
  78.         beq.s   SETCACHX
  79.  
  80.         cmpi.b  #$40,$A1(a6)
  81.         blt.s   SETCACH2030
  82.  
  83.         cinva   ic/dc
  84.  
  85. SETCACH2030:
  86.         movec   d0,cacr
  87.  
  88. SETCACHX:
  89.         rts
  90.  
  91. C68 can be fixed by replacing the above routines as follows:
  92.  
  93. *******************************************************************
  94. *
  95. * routine to disable the instruction & data caches
  96. * Exit: d0 = previous CACR value
  97. *
  98. CACHOFF:
  99.         moveq   #0,d0
  100.  
  101. *******************************************************************
  102. *
  103. * routine to set the CACR
  104. * Entry: d0 = value to write to CACR
  105. * Exit: d0 = previous CACR value
  106. *
  107. SETCACH:
  108.         move.l  d1,-(a7)
  109.  
  110.         cmpi.b  #$10,$A1(a6)
  111.         bls.s   SETCACHX        exit if 010 or less
  112.  
  113.         movec   cacr,d1
  114.         exg     d1,d0           old cacr value => d0
  115.  
  116.         ori.w   #$0808,d1       on 020/030 always clear caches
  117.  
  118.         cmpi.b  #$30,$A1(a6)
  119.         bls.s   SETCACHSET
  120.  
  121.         tst.w   d0              check 040 bits
  122.         bpl.s   SETCACHDCHK     branch if instruction cache off
  123.         cpusha  ic              otherwise update memory from cache
  124.  
  125. SETCACHDCHK:
  126.         tst.l   d0              check 040 bits
  127.         bpl.s   SETCACHDINV     branch if data cache off
  128.         cpusha  dc              otherwise update memory from cache
  129.  
  130.         tst.l   d1              check 040 bits
  131.         bmi.s   SETCACHIINV     branch if leaving data cache on
  132.  
  133. SETCACHDINV:
  134.         cinva   dc              invalidate cache
  135.  
  136. SETCACHIINV:
  137.         cinva   ic              invalidate cache
  138.  
  139. SETCACHSET:
  140.         movec   d1,cacr         set the cache
  141.  
  142. SETCACHX:
  143.         move.l  (a7)+,d1
  144.         rts
  145.  
  146. *******************************************************************
  147.  
  148. CONTACT
  149.  
  150.   post: MARK J SWIFT          e-mail: msw@blackpool.ac.uk
  151.         175 CHURCH STREET
  152.         BLACKPOOL
  153.         LANCS
  154.         FY1 3NX
  155.